package com.mllweb.blog.service.impl;

import com.mllweb.blog.data.dao.BlogArticleCategoryDao;
import com.mllweb.blog.data.dao.BlogArticleDao;
import com.mllweb.blog.data.orm.BlogArticle;
import com.mllweb.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 文章服务
 */
@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private BlogArticleDao blogArticleDao;
    @Autowired
    private BlogArticleCategoryDao blogArticleCategoryDao;

    @Transactional
    @Override
    public void insert(BlogArticle article, int categoryId) {
        blogArticleDao.insertArticle(article);
        blogArticleCategoryDao.insert(article.getId(), categoryId);
    }

    @Override
    public BlogArticle select(int id) {
        return blogArticleDao.select(id);
    }

    @Override
    public List<BlogArticle> selectByCategoryId(int id) {
        return blogArticleDao.selectByCategoryId(id);
    }
}
